function WindSlashDamage takes nothing returns nothing
	local unit target = GetEnumUnit()
	local real realDamage = udg_TempDamage
	//--
	if (IsUnitEnemy(target , udg_TempPlayer) and IsUnitInRangeLoc(target , udg_TempCasterLocation , udg_TempRadius) and not IsUnitType(target , UNIT_TYPE_STRUCTURE) and GetUnitState(target , UNIT_STATE_LIFE) > 0.0) then
		set udg_TempHitCount = udg_TempHitCount + 1
		call UnitDamageTarget(udg_TempCaster , target , realDamage , true , false , ATTACK_TYPE_NORMAL , DAMAGE_TYPE_COLD , WEAPON_TYPE_METAL_MEDIUM_SLICE)
	endif
	//--
	set target = null
endfunction

function WindSlashActionEffect takes nothing returns nothing
	local timer delayTimer = GetExpiredTimer()
	local integer timerId = GetHandleId(delayTimer)
	local real mastery = 0
	local unit caster = LoadUnitHandle(udg_HT , timerId , StringHash("CASTER"))
	local integer abilityLevel = GetUnitAbilityLevel(caster , 'A021')
	local item weapon = LoadItemHandle(udg_HT , timerId , StringHash("WEAPON"))
	local real weaponDamage = LoadReal(udg_ItemDataHashTable , GetHandleId(weapon) , StringHash("WEAPON_DAMAGE"))
	local real weaponRangeBonus = LoadReal(udg_ItemDataHashTable , GetHandleId(weapon) , StringHash("RANGE_BONUS"))
	//--
	set udg_TempCaster = caster
	set udg_TempPlayer = GetOwningPlayer(caster)
	set mastery = LoadReal(udg_UnitDataHashTable , GetHandleId(caster) , StringHash("WIND_SLASH_MASTERY"))
	set udg_TempDamage = 20.0 + weaponDamage * 0.1 * mastery
	set udg_TempHitCount = 0
	set udg_TempRadius = 100.0 + I2R(abilityLevel - 1) * 20.0 + weaponRangeBonus
	set udg_TempCasterLocation = GetUnitLoc(caster)
	call For(GetUnitsInRangeOfLocMatching(udg_TempRadius + 70.0 , udg_TempCasterLocation , null) , function WindSlashDamage)
	call UnitUsedAbilityWithDelta(caster , 'A021' , 1.0 + I2R(udg_TempHitCount) * 0.3)
	
	call RemoveLocation(udg_TempCasterLocation)
	call PauseTimer(delayTimer)
	call FlushChildHashtable(udg_HT , timerId)
	call DestroyTimer(delayTimer)
	//--
	set delayTimer = null
	set caster = null
endfunction

function WindSlashAction takes nothing returns nothing
	local timer delayTimer = CreateTimer()
	local integer timerId = GetHandleId(delayTimer)
	local unit caster = GetTriggerUnit()
	//--
	call SaveUnitHandle(udg_HT , timerId , StringHash("CASTER") , caster)
	call SaveItemHandle(udg_HT , timerId , StringHash("WEAPON") , GetWeaponOfType(caster , StringHash("TWO_HANDED")))
	call TimerStart(delayTimer , 0.2 , false , function WindSlashActionEffect)
	call UnitPlayAnimation(caster , 63 , 2.5 , 0.4)
	//--
	set delayTimer = null
	set caster = null
endfunction

function Trig_WindSlashTryActions takes nothing returns nothing
	if GetSpellAbilityId() == 'A021' then
		call WindSlashAction()
	endif
endfunction

function InitTrig_WindSlash takes nothing returns nothing
	local hashtable masteryTable = InitHashtable()
	local integer abilityId = 'A021'
	//--	
	//call SaveInteger(udg_AbilityDataHashTable , abilityId , StringHash("NEXT_ABILITY") , 'A01X')
	call SaveInteger(udg_AbilityDataHashTable , abilityId , StringHash("HOTKEY") , StringHash("W"))
	call SaveInteger(udg_AbilityDataHashTable , abilityId , StringHash("MASTERY_ID") , StringHash("WIND_SLASH_MASTERY"))
	call SaveStr(udg_AbilityDataHashTable , abilityId , StringHash("NAME") , "迴旋斬")
	call SaveInteger(udg_AbilityDataHashTable , abilityId , StringHash("MAX_LEVEL") , 3)
	call SaveHashtableHandle(udg_AbilityDataHashTable , abilityId , StringHash("LEVEL_MASTERY_TABLE") , masteryTable)
	call SaveReal(masteryTable , 1 , 0 , 20.0) //30
	call SaveReal(masteryTable , 2 , 0 , 60.0) //70
	call SaveReal(masteryTable , 3 , 0 , 120.0) //120
	
	set gg_trg_WindSlash = CreateTrigger()
	call TriggerRegisterPlayerForceUnitEvent(gg_trg_WindSlash , EVENT_PLAYER_UNIT_SPELL_EFFECT )
	call TriggerAddAction(gg_trg_WindSlash , function Trig_WindSlashTryActions)
	//--
	set masteryTable = null
endfunction